<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>流程任务管理</title>
    <#include "/pubHeadStyle.html">
</head>
<body>
<div style="position: relative;height: 100%;">
    <div class="tablesize roles taskTable" style="">
        <table id="processTask" lay-filter="processTask">
        </table>
    </div>
    <div class="tablesize roles" style="position: absolute;top:0;right:0px;bottom: 0; padding:10px;">
        <div class="taskDetails">
            <p class="clearfix">
                <i class="layui-icon layui-icon-prev prevs"></i>
                <span>任务明细</span>
            </p>
            <table class="table-detail tableDetails" style="display: none">
                <tr>
                    <th>流程事项名称</th>
                    <td><span class="subjects">无</span></td>
                </tr>
                <tr>
                    <th>任务ID</th>
                    <td><span class="id">无</span></td>
                </tr>
                <tr>
                    <th> 流程运行(RUNID) </th>
                    <td><span class="runId">无</span></td>
                </tr>
                <tr>
                    <th>任务名</th>
                    <td><span class="name">无</span></td>
                </tr>
                <tr>
                    <th>任务描述</th>
                    <td><p class="description">无</p></td>
                </tr>
                <tr>
                    <th>执行人</th>
                    <td><p style="display: inline-block;" class="assignee">无</p><a class="layui-btn layui-btn-sm changeOperator" style="margin-left: 10px">更改...</a></td>
                </tr>
                <tr>
                    <th>候选执行人</th>
                    <td><p class="users">无</p></td>
                </tr>
                <tr>
                    <th>当前活动任务</th>
                    <td><p class="taskList">无</p></td>
                </tr>
                <tr>
                    <th>创建时间</th>
                    <td><p class="createTime">无</p></td>
                </tr>
                <tr>
                    <th>到期时间</th>
                    <td><p class="dueDate">无</p></td>
                </tr>
                <tr>
                    <th>流程定义名称</th>
                    <td><span class="subject">无</span></td>
                </tr>
                <tr>
                    <th>版本</th>
                    <td><span class="versionNo">无</span></td>
                </tr>
                <tr>
                    <th> 流程定义描述 </th>
                    <td><span class="descp">无</span></td>
                </tr>
            </table>
        </div>
    </div>
</div>
<style>
    .clearfix:after{content:"";display:block;clear:both;height:0;line-height:0;visibility:hidden;}
    .clearfix{zoom:1;}
    .ulPanel li:hover{
        background-color: #f2f2f2;
    }
    .ulPanel li{
        padding-left: 10px;
        cursor: pointer;
    }
    .taskTable{
        position: absolute;top:0;right:40px;bottom: 0;left: 0px; padding:10px
    }
    div.taskTableShou{
        right:405px;
    }
    .taskDetails > p{
        background: #e6e6e6;
    }
    .taskDetails>p>i{
        margin: 10px 5px;
        width: 16px;
        cursor: pointer;
        float: left;
    }
    .taskDetails > p >span{
        display: none;
        float: left;
        line-height: 37px;
    }
    .taskDetails{
        width: 30px;border: 1px solid #e6e6e6;height: 100%;
    }
    .tableDetails th{
        width: 125px;
    }
    div.Open{
        width: 400px;

    }
    div.Open>p>i{
        margin: 10px;
    }
</style>
<script type="text/html" id="headerToolsBar">
    <div class="ccpui-enterSel">
    <div class="layui-btn-container">
        <a class="layui-btn layui-btn-sm" lay-event="query">
            <i class="layui-icon layui-icon-search"></i>
            <span>查询</span>
        </a>
        <a class="layui-btn layui-btn-sm" lay-event="reset">
            <i class="layui-icon layui-icon-refresh"></i>
            <span>重置</span>
        </a>
    </div>
    <form class="layui-form" action="" lay-filter="processTaskQueryForm" style="margin-top:10px">
        <div class="table-top-filter">
            <div class="table-filter-alone">
                <label class="layui-form-label">流程定义名称</label>
                    <input type="text" name="Q_processName_SL" id="Q_processName_SL" class="layui-input filter-value"
                       placeholder="流程定义名称"/>
            </div>
            <div class="table-filter-alone">
                <label class="layui-form-label">事项名称</label>
                <input type="text" name="Q_subject_SL" id="Q_subject_SL" class="layui-input filter-value"
                       placeholder="事项名称"/>
            </div>
            <div class="table-filter-alone">
                <label class="layui-form-label">任务名称</label>
                <input type="text" name="Q_name_SL" id="Q_name_SL" class="layui-input filter-value"
                       placeholder="任务名称"/>
            </div>
            <div class="table-filter-alone">
                <label class="layui-form-label">任务ID</label>
                <input type="text" name="Q_id_SL" id="Q_id_SL" class="layui-input filter-value"
                       placeholder="任务ID"/>
            </div>
            <div class="table-filter-alone">
                <label class="layui-form-label">工单号</label>
                <input type="text" name="Q_globalFlowNo_SL" id="Q_globalFlowNo_SL" class="layui-input filter-value"
                       placeholder="工单号"/>
            </div>
            <div class="table-filter-alone">
                <label class="layui-form-label">执行人</label>
                <input type="text" name="Q_assignee__SL" id="Q_assignee__SL" class="layui-input filter-value"
                       placeholder="执行人"/>
            </div>
        </div>
    </form>
    </div>
</script>

<script>
    layui.config({
        base: serverPath.systemPath + staticPath.systemPath //静态资源所在路径
    }).extend({
        index: 'index' //主入口模块
    }).use(['index','table', 'layer', 'util', 'commons', 'setter', 'totalFilter', 'common','admin'], function () {
        var table = layui.table;
        var layer = layui.layer;
        var util = layui.util;
        var $ = layui.$;
        var setter = layui.setter;
        var commons = layui.commons;
        var common = layui.common;
        var totalFilter = layui.totalFilter;
        var admin = layui.admin;
        var dataPrivacyLevel = 1;
        var privacyLevel = ${privacyLevel};
        var tableH = commons.tabHeight();
        loadTable(serverPath.workflowPath + setter.workflowLinkPath + 'task/list');
        //第一个实例
        function loadTable(url) {
            table.render({
                elem: '#processTask'
                , cellMinWidth: 80
                , title: '流程任务管理'
                , height: tableH
                , url: url
                , method: 'post'
                , toolbar: '#headerToolsBar'
                ,defaultToolbar: ['filter', 'print']
                ,autoSort: false
                , page: true
                , cols: [[
                    {field: 'globalFlowNo', title: '工单号', sort: true, align: 'center'}
                    , {
                        event: 'doNext',
                        field: 'subject',
                        title: '事项名称',
                        minWidth: 330,
                        sort: true,
                        align: 'center', style: 'color:#1E9FFF;cursor: pointer',
                    }
                    , {field: 'name', title: '任务名称', sort: true, align: 'center'}
                    , {
                        field: 'assigneeName',
                        title: '执行人',
                        align: 'center',
                        style: 'color:#1E9FFF',
                        templet: function (d) {
                            return returnAssigneeName(d.assignee,d.assigneeName,d.assignees);
                        }
                    }
                    , {
                        field: 'delegation_', title: '状态', sort: true, align: 'center', templet: function (d) {
                            if (d.delegationState === '') {
                                return "待运行";
                            } else {
                                return d.delegationState;
                            }
                        }
                    }
                    , {
                        field: 'CREATE_TIME_', title: '任务创建时间',minWidth: 200, sort: true, align: 'center', templet: function (d) {
                            return returnDateTime(d.createTime);
                        }
                    }
                ]]
                ,done:function () {
                    common.tableSelectCon('.ccpui-enterSel .layui-form input','a[lay-event=query]','.ccpui-enterSel')
                }
            });
            totalFilter.init('processTask');
        }
        //提取公共方法，回显时间
        function returnDateTime(_time) {
            if (_time == undefined) {
                return "";
            } else {
                return util.toDateString(_time, "yyyy-MM-dd HH:mm:ss");
            }
        }
        //提取公共方法，回显任务执行人
        function returnAssigneeName(_assignee,_assigneeName,_assignees) {
            var html = '';
            if (_assignee != null && _assignee != 0) {
                html += "<a onclick=authUserClick('" + _assignee + "') href='javascript:void(0);' style='color: blue;margin-right: 5px;'>" + _assigneeName + "</a> ";
            } else {
                layui.each(_assignees, function (index, item) {
                    var userId = item.executeId;
                    var userName = item.executor;
                    var type = item.type;
                    if (type === "org") {
                        html += "<div class='roleDiv' style='position: relative;'><a onclick=roleOrgClick('" + userId + "','org') id='" + userId + "' href='javascript:void(0);' style='color: blue    ;margin-right: 5px;'>" + userName + "</a><ul class='ulPanel' style='display: none'></ul></div>" + '&nbsp;&nbsp;';
                    } else if (type === "role") {
                        html += "<div class='roleDiv' style='position: relative;'><a onclick=roleOrgClick('" + userId + "','role') id='" + userId + "' href='javascript:void(0);' style='color: blue;margin-right: 5px;'>" + userName + "</a><ul class='ulPanel' style='display: none'></ul></div>" + '&nbsp;&nbsp;';
                    } else if (type === "user") {
                        html += "<a onclick=authUserClick('" + userId + "') href='javascript:void(0);' style='color: blue;margin-right: 5px;'>" + userName + "</a> " + '&nbsp;&nbsp;';
                    }
                })
            }
            return html;
        }

        //回显当前活动任务
        function returnTaskList(taskList){
            var task = '';
            var _length = taskList.length;
            for(var i=0;i<_length;i++){
                // 人名一个图片和一个点击事件
                task += taskList[i].name+'(<i class="layui-icon layui-icon-friends"></i> '+returnAssigneeName(taskList[i].assignee,taskList[i].assigneeName,taskList[i].assignees)+')' ;
                if(i!=(_length-1)){
                    task += ",";
                }
            }
            return task;
        }
        //回显任务描述，判断条件来源TaskOpinion实体类
        function returnDescription(_description){
            switch (_description) {
                case "-2" : return "初始化\\尚未审批";
                case "-1" : return "正在审批";
                case  "0" : return "弃权";
                case  "1" : return "同意";
                case  "2" : return "反对";
                case  "3" : return "驳回";
                case  "4" : return "撤销";
                case  "5" : return "会签通过";
                case  "6" : return "会签不通过";
                case  "7" : return "知会意见";
                case  "8" : return "更改执行路径";

                case "14" : return "终止";
                case "15" : return "沟通意见";
                case "16" : return "办结转发";
                case "17" : return "撤销";
                case "18" : return "逻辑删除";
                case "19" : return "抄送";
                case "20" : return "沟通反馈";
                case "21" : return "转办";
                case "22" : return "转办取消";
                case "23" : return "更改执行人";
                case "24" : return "驳回到发起人";
                case "25" : return "撤销到发起人";
                case "26" : return "代理";
                case "27" : return "代理撤消";
                case "28" : return "表单意见";
                case "29" : return "驳回取消";
                case "30" : return "撤销取消";
                case "31" : return "通过取消";
                case "32" : return "拒绝取消";
                case "33" : return "提交";
                case "34" : return "重新提交";
                case "35" : return "干预";
                case "36" : return "重启任务";
                case "37" : return "执行过，用于自动节点记录状态";
                case "38" : return "流转";
                case "39" : return "流转中";
                case "40" : return "代提交";
                case "41" : return "正常流转，即无别人干预";
                case "42" : return "流转取消";
                case "43" : return "添加流转人";
                case "44" : return "补签";
                case "45" : return "追回";
            }
        }
        // 监听行工具事件
        table.on('toolbar(processTask)', function (obj) {
            switch (obj.event) {
                case 'query':
                    common.tableConditionRender("processTask", "processTaskQueryForm", {where: {}}, false);
                    break;
                case 'reset':
                    common.tableConditionRender("processTask", "processTaskQueryForm", {where: {}}, true);
                    break;
            }
        });
        table.on('tool(processTask)', function (obj) {
            var data = obj.data;
            switch (obj.event) {
                case 'doNext':
                    // 获取密级
                    $.ajax({
                        url: serverPath.workflowPath + setter.workflowLinkPath+"processRun/getPrivacyLevelByRunId",
                        data:{runId: data.runId},
                        type: "post",
                        dataType: 'json',
                        success: function (result) {
                            dataPrivacyLevel = result;
                            if (privacyLevel < dataPrivacyLevel) {
                                layer.msg('密级不足,无法查看该实例内容', {icon: 5});
                            }else{
                                var isModify = true;
                                parent.layer.open({
                                    type: 2,
                                    title: "流程任务",
                                    shade: 0.3,
                                    left: 200,
                                    area: ['1300px', '650px'],
                                    content: serverPath.workflowPath +  setter.workflowLinkPath +"task/view/doNext?taskId=" + data.id + "&runId=" + data.runId,
                                    cancel: function(index, layero){
                                        isModify = false;
                                    },
                                    end: function () {
                                        if (isModify){
                                            table.reload('processTask', {
                                                page: {
                                                    curr: 1,limit: 10
                                                }
                                            });
                                            totalFilter.init('processTask');
                                        }

                                    }
                                });                            }
                        }
                    });

                    break;
            }
        });
        // 点击执行人员弹窗
        authUserClick = function (userId) {
            layer.open({
                type: 2,
                area: ['1000px', '620px'],
                title: ['查看用户信息'],
                content: serverPath.systemPath + setter.sysLinkPath+'sysUser/view/view?userId=' + userId
            });
        };
        // 点击显示角色(组织)下的人员
        roleOrgClick = function (roleId,type) {
            var url='';
            if (type == 'org'){
                url = serverPath.systemPath + setter.sysLinkPath +"sysUser/queryUserListByOrgId?orgId=" + roleId;
            }else {
                url = serverPath.systemPath + setter.sysLinkPath +"sysUser/queryUserListByRoleId?roleId=" + roleId;
            }
            $.ajax({
                url:url,
                dataType: 'json',
                type: "get",
                success:function (result) {
                    $("#"+roleId).siblings('ul').html('');
                    $("#"+roleId).parent().parent().css("overflow","unset");
                    $.each(result,function (index,tim) {
                        $("#"+roleId).siblings('ul').append('<li onclick=authUserClick("' + tim.userId + '")>'+tim.fullName+'</li>');
                    });
                    $("#"+roleId).siblings('ul').show().css({'position':'absolute','top':'33px','left':'0','border':'1px solid #d2d2d2','overflow-y':'auto','height':'300px','width':'100%','background':'#fff','z-index':'10','text-align':'left'});
                    $(document).one('click',':not(.ulPanel)',function(){
                        $(".ulPanel").hide();
                        return;
                    })
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    layer.alert("操作失败！" + XMLHttpRequest.status);
                }
            });
        };
        //点击明细按钮 展开面板
        $('.taskDetails>p>i').click(function () {
            $(this).parent().parent().toggleClass('Open');
            $(this).parent().parent().parent().prev().toggleClass("taskTableShou");
            $(this).toggleClass("layui-icon-next");
            $(this).siblings('span').toggle();
            $(this).parent().siblings('.tableDetails').toggle();
            //执行表格“尺寸结构”的重置，一般写在对应的事件中
            table.resize('processTask');
        });
        //监听行单击事件,任务明细右隐藏窗口
        table.on('row(processTask)', function(obj){
            $.ajax({
                method: 'post',
                url: serverPath.workflowPath + setter.workflowLinkPath+"task/miniDetail",
                data: {
                    taskId:obj.data.id,
                },
                dataType: 'json',
                success: function (res) {
                    var _data = res.data;
                    $(".subjects").text(_data.subject);
                    $(".taskList,.assignee").html("")
                    $(".assignee").append(returnAssigneeName(_data.assignee,_data.assigneeName,_data.assignees));
                    $(".taskList").append(returnTaskList(_data.taskList));
                    $(".createTime").text(returnDateTime(_data.createTime));
                    $(".descp").text(_data.actDescription==null?"无":_data.actDescription);
                    $(".description").text(_data.description?returnDescription(_data.description):_data.name);
                    $(".dueDate").text(returnDateTime(_data.dueDate));
                    $(".id").text(_data.id);
                    $(".name").text(_data.name);
                    $(".runId").text(_data.runId);
                    $(".subject").text(_data.actName);
                    $(".versionNo").text(_data.actVersion);
                    if (res.data.users.length>0){
                        $(".users").text("");
                        $.each(res.data.users,function (i,val) {
                            $(".users").append("<span>"+val.executor+"</span>");
                        })
                    }
                }});
            //obj.del(); //删除当前行
            //obj.update(fields) //修改当前行数据
            $(".changeOperator").unbind().click(function () {
                parent.layer.open({
                    type: 2,
                    title: "流程任务",
                    content: serverPath.workflowPath +  setter.workflowLinkPath +"task/view/changeAssignee?taskId=" + obj.data.id + "&dataPrivacyLevel=" + dataPrivacyLevel,
                    shade: 0.3,
                    area: ['1050px', '620px'],
                    btn:['确定','取消'],
                    yes:function(index,layero){
                        //获取iframe的body元素
                        var body = parent.layer.getChildFrame('body',index);
                        //得到iframe页的窗口对象
                        var iframeWin = parent.window[layero.find('iframe')[0]['name']];
                        var informType;
                        if (body.find("#jumpUserDivHidden").val()!=''){
                            if (body.find("#voteContent").val()!='') {
                                if (body.find("input[name=informType]").prop('checked')) {
                                    informType = body.find("#informType").val()
                                }
                                $.ajax({
                                    url: serverPath.workflowPath + setter.workflowLinkPath + "task/changeAssignee?",
                                    type: "post",
                                    dataType: 'json',
                                    data: {
                                        taskId:body.find("#taskId").val(),
                                        userId:body.find("#jumpUserDivHidden").val(),
                                        voteContent:body.find("#voteContent").val(),
                                        informType:informType,
                                    },
                                    success: function (result) {
                                        if (result.code==0){
                                            parent.layer.close(index);
                                            parent.layer.msg(result.msg, {icon: 1, time: 500});
                                            $('.prevs').parent().parent().removeClass('Open');
                                            $('.prevs').parent().parent().parent().prev().removeClass("taskTableShou");
                                            $('.prevs').removeClass("layui-icon-next");
                                            $('.prevs').siblings('span').hide();
                                            $('.prevs').parent().siblings('.tableDetails').hide();
                                            $('.prevs').parent().siblings('.tableDetails').find('span,p').text('无');
                                            table.reload('processTask', {
                                                page: {
                                                    curr: 1,limit: 10
                                                }
                                            });
                                            totalFilter.init('processTask');
                                        }else {
                                            parent.layer.msg(result.msg, {icon: 2, time: 2000});
                                        }
                                    },
                                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                                        parent.layer.alert("操作失败！" + XMLHttpRequest.status);
                                    }
                                });
                            }else {
                                parent.layer.msg('请填写更改任务执行人原因!', {icon: 0, time: 500});
                            }
                        }else {
                            parent.layer.msg('请选择执行人!', {icon: 0, time: 500});
                        }
                    }
                });
            });
        });
        common.tableSort("processTask",{});
    });
</script>
</body>
</html>
<link rel="stylesheet" href="${ctx}/css/font/iconfontie.css" media="all"/>
<link rel="stylesheet" href="${ctx}/iconfont/iconfont.css"/>
